package com.neusoft.neuiotms.dcom.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractModel;
import com.neusoft.bizcore.web.jpa.model.Comment;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@Entity
@org.hibernate.annotations.Table(appliesTo = "neuiot_duty_arrangement", comment = "值班安排表")
@Table(name = "neuiot_duty_arrangement")
public class DutyArrangement extends AbstractModel {

    private static final long serialVersionUID = 1L;

    /** 值班名称 */
    @NotBlank(message = "值班名称不能为空")
    @Length(max = 255, message = "值班名称不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '值班名称'")
    private String name;

    /** 组织名称 */
    @NotBlank(message = "组织名称不能为空")
    @Length(max = 255, message = "组织名称不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '组织名称'")
    private String orgName;

    /** 组织代码 */
    @NotBlank(message = "组织代码不能为空")
    @Length(max = 255, message = "组织代码不能超过{max}位")
    @Column(length = 255, nullable = false)
    private String orgCode;

    /** 开始时间 */
    @Column(length = 6, nullable = false)
    @Comment("datetime(6) NOT NULL COMMENT '开始时间'")
    private Date startTime;

    /** 结束时间 */
    @Column(length = 6, nullable = false)
    @Comment("datetime(6) NOT NULL COMMENT '结束时间'")
    private Date endTime;

    /** 关联组 */
    @OneToMany(mappedBy = "group", cascade = {CascadeType.ALL })
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<DutyArrangementGroup> groups = new ArrayList<>();

    /** 关联规则 */
    @ManyToOne
    private SchedulingRule schedulingRule;

    /** 关联职能 */
    @ManyToOne
    private FunctionalGroup functionalGroup;

    /** 是否已删除 */
    @Column(nullable = false)
    @Comment("bit(1) NOT NULL COMMENT '是否已删除'")
    private Boolean deleteFlag = false;

}
